import { Space, Divider } from 'antd'
import { ColumnsType } from 'antd/es/table'
import { ConfigSchema } from './ajax'
import { formatDate } from '@js/tool'

export function getColumn (setModifyData: (v: ConfigSchema) => void, setVisible: (v: boolean) => void): ColumnsType<ConfigSchema> {
  const columns: ColumnsType<ConfigSchema> = [
    {
      title: '序号',
      dataIndex: 'orderno',
      key: 'orderno',
      width: 75
    },
    {
      title: '名称',
      dataIndex: 'name',
      key: 'name'
    },
    {
      title: '答辩期',
      dataIndex: 'defence_period',
      key: 'defence_period',
      render: (v: number) => {
        if (typeof v === 'number') {
          return `${v}天`
        }
      }
    },
    {
      title: '审限',
      dataIndex: 'processing_period',
      key: 'processing_period',
      render: (v: number) => {
        if (typeof v === 'number') {
          return `${v}天`
        }
      }
    },
    {
      title: '生效日期',
      dataIndex: 'effective_datetime',
      key: 'effective_datetime',
      render: (v: number) => {
        if (typeof v === 'number') {
          return formatDate(v, 'YYYY-MM-DD')
        }
      }
    },
    {
      title: '操作',
      dataIndex: 'id',
      key: 'id',
      width: 135,
      render: (v: string, l: ConfigSchema) => {
        return (
          <Space split={<Divider type="vertical" />}>
            <a onClick={() => { setModifyData(l); setVisible(true) }}>编辑</a>
          </Space>
        )
      }
    }
  ]
  return columns
}
